package com.jt.tenant.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetGasStationList;

import java.util.List;

/**
 * Created by Administrator on 2016/4/7.
 */
public class GasStationListAdapter extends BaseAdapter {

    private Context context;

    private List<GetGasStationList.GSList> list;

    public GasStationListAdapter(Context context, List<GetGasStationList.GSList> list) {

        this.context = context;

        this.list = list;

    }

    @Override
    public int getCount() {

        return list.size();

    }

    @Override
    public Object getItem(int position) {

        return list.get(position);

    }

    @Override
    public long getItemId(int position) {

        return position;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {

            convertView = View.inflate(context, R.layout.item_gslist, null);

            JTApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);

            holder = new ViewHolder();

            holder.gs_logo = (ImageView)convertView.findViewById(R.id.iv_gs_logo);

            holder.gs_state  = (TextView)convertView.findViewById(R.id.gs_state);

            holder.gs_name = (TextView) convertView.findViewById(R.id.gs_name);

            holder.gs_location = (TextView) convertView.findViewById(R.id.gs_location);

            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();

        }
        switch (list.get(position).FLAG){

            case "0":

                holder.gs_state.setText("预约");

                break;

            case "1":

                holder.gs_state.setText("");

                break;

            case "2":

                holder.gs_state.setText("去加油");

                break;

        }

        JTApplication.UtilAsyncBitmap.get(list.get(position).URL, holder.gs_logo, R.mipmap.loading);

        holder.gs_name.setText( list.get(position).GAS_NAME);

        holder.gs_location.setText(list.get(position).GAS_ADDRESS);

        return convertView;

    }

    class ViewHolder {
        private ImageView gs_logo;
        private TextView gs_name;
        private TextView gs_location;
        private TextView gs_state;

    }
}
